package cn.wp.ewallet.upms.dao.impl;

import cn.wp.common.core.dao.JdbcSupportTemplate;
import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.common.extension.constant.EwalletConstant;
import cn.wp.ewallet.upms.dao.SysLoginUserDoDao;
import cn.wp.ewallet.upms.model.entity.SysLoginUserDoo;
import cn.wp.ewallet.upms.model.entity.SystemUserInfoDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName SystemUserInfoDaoImpl
 * @Author ruixule
 * @Description TODO
 * @Date 2019/12/25 12:13
 */
@Repository
public class SysLoginUserDoDaoImpl implements SysLoginUserDoDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;


    @Override
    public List<SysLoginUserDoo> selectLoginUserDooByAccount(String account) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select a.*, b.OBJECT_ID, b.OBJECT_TYPE, c.ROLE_ID, c.ROLE_NAME");
        sqlString.add("    , c.ROLE_TYPE");
        sqlString.add("from system_user_info a, pa_object_role_rel b, bs_role_info c");
        sqlString.add("where a.SYS_USER_ID = b.OBJECT_ID");
        sqlString.add("    and b.ROLE_ID = c.ROLE_ID");
        sqlString.add("    and a.PWD_STATUS = ?");
        sqlString.add("    and a.STATUS = ?");
        sqlString.add("    and b.STATUS = ?");
        sqlString.add("    and b.STATUS = ?");
        sqlString.add("    and a.SYS_USER_CODE= ?");

        Object[] params = new Object[]{
                EwalletConstant.INVALID_STATUS,
                EwalletConstant.STATUS,
                EwalletConstant.STATUS,
                EwalletConstant.STATUS,
                account
        };

        return jdbcSupportTemplate.selectList(sqlString.build(), params, SysLoginUserDoo.class);
    }

    @Override
    public SystemUserInfoDo selectLoginUserDoByUserId(String userId) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select *");
        sqlString.add("from system_user_info");
        sqlString.add("where SYS_USER_ID = ?");
        return jdbcSupportTemplate.selectObject(sqlString.build(),new Object[]{userId},SystemUserInfoDo.class);
    }

    @Override
    public void updatePassword(SystemUserInfoDo systemUserInfoDo) {
        jdbcSupportTemplate.update(systemUserInfoDo);
    }
}
